package com.yeyks.common.utils;

import java.util.function.Supplier;

public class TryCatchUtil {

    public static <T> T tryCatch(Supplier<T> supplier) {
        return tryCatch(supplier, false);
    }

    public static <T> T tryCatch(Supplier<T> supplier, boolean outE) {
        try {
            return supplier.get();
        } catch (Exception e) {
            if (outE) {
                e.printStackTrace();
            }
        }
        return null;
    }

    public static void tryCatch(DoSomeThing doSomeThing) {
        tryCatch(doSomeThing, false);
    }

    public static void tryCatch(DoSomeThing doSomeThing, boolean outE) {
        try {
            doSomeThing.doSomeThing();
        } catch (Exception e) {
            if (outE) {
                e.printStackTrace();
            }
        }
    }

    public interface DoSomeThing {
        void doSomeThing();
    }

}
